package com.zhida.smartcontrol.dialog.lampkzlxdialog;

import android.text.TextUtils;

import com.zhida.smartcontrol.common.Api;
import com.zhida.smartcontrol.common.Const;
import com.zhida.smartcontrol.common.bean.LampSwitchBean;
import com.zhida.smartcontrol.knet.KalleCallBack;
import com.zhida.smartcontrol.mvp.BasePresenterImpl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LampKzlxDialogPresenter extends BasePresenterImpl<LampKzlxDialogContract.View> implements LampKzlxDialogContract.Presenter {

    @Override
    public void changeSet(int switchType, List<LampSwitchBean> codeList, String type) {
        String url = switchType == Const.ZIG_BEE_SINGLE ? Api.HAND_AUTO_SET_ZIGBEE : Api.HAND_AUTO_SET;

        List<String> list = new ArrayList<>();
        for (LampSwitchBean lampBean : codeList) {
            if (switchType == Const.ZIG_BEE_SINGLE) {
                list.add(lampBean.getId());
            } else {
                list.add(lampBean.getCode());
            }
        }
        if (TextUtils.isEmpty(type)) {
            mView.showMsg("请选择一个控制类型");
            return;
        }
        Map<String, Object> params = new HashMap<>();
        params.put("codeList", list);
        params.put("type", type);//1手动，0自动
        mKalleCenter.postJson(url, params, true, new KalleCallBack() {
            @Override
            public void onSuccess(String result, String msg) {
                if (null != mView) {
                    mView.showMsg(msg);
                    mView.onSuccess();
                }
            }

            @Override
            public void onFailed(String msg) {
                if (null != mView)
                    mView.showMsg(msg);
            }
        });
    }
}
